//
//  HCVIPView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/21.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCVIPView.h"

#import "WZLabel.h"

#import "HCVipModel.h"

@interface HCVIPView () {
    UIImageView *imageView;
    UILabel *bottomLabel;
    WZLabel *label;
    UIView *midView;
    WZLabel *dateLabel;
}

@end

@implementation HCVIPView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubView:frame];
    }
    return self;
}

-(void)initializeSubView:(CGRect)frame {
    
    self.backgroundColor = YBKRGBCOLOR(242, 242, 242, 1);
    
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - YBKAdaptiveW(323))/2.0, YBKAdaptiveH(32),YBKAdaptiveW(323) , YBKAdaptiveW(300))];
    imageView.image = [UIImage imageNamed:@"happy_vip_vipbgc"];
    [self addSubview:imageView];
    
    midView = [[UIView alloc] initWithFrame:CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y+imageView.frame.size.height, imageView.frame.size.width, YBKAdaptiveW(93))];
    midView.backgroundColor = [UIColor whiteColor];
    [self addSubview:midView];
    
    label = [[WZLabel alloc] initWithFrame:CGRectMake(0, 0, midView.frame.size.width, midView.frame.size.height/2.0)];
    label.textColor = YBKRGBCOLOR(240, 96, 96, 1);
    label.font = [UIFont boldSystemFontOfSize:YBKAdaptiveFont(20)];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"";
    label.verticalAlignment = WZVerticalAlignmentBottom;
    [midView addSubview:label];
    
    dateLabel = [[WZLabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame)+5, midView.frame.size.width, midView.frame.size.height/2.0)];
    dateLabel.textColor = YBKRGBCOLOR(240, 96, 96, 1);
    dateLabel.font = [UIFont boldSystemFontOfSize:YBKAdaptiveFont(16)];
    dateLabel.textAlignment = NSTextAlignmentCenter;
    dateLabel.text = @"";
    [midView addSubview:dateLabel];
    
    UIImage *im = [UIImage imageNamed:@"happy_vip_no"];
    
    UIImageView *bottomBG = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - YBKAdaptiveW(im.size.width))/2.0, frame.size.height - YBKAdaptiveW(im.size.height) - YBKAdaptiveW(50), YBKAdaptiveW(im.size.width), YBKAdaptiveW(im.size.height))];
    bottomBG.image = im;
    [self addSubview:bottomBG];
    
    bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, bottomBG.frame.size.width, bottomBG.frame.size.height)];
    bottomLabel.font = YBKSystemFont(YBKAdaptiveFont(15));
    bottomLabel.textColor = [UIColor whiteColor];
    bottomLabel.text = @"1231239879868";
    [bottomBG addSubview:bottomLabel];
    
    CGSize imSize = [bottomLabel sizeThatFits:CGSizeMake(bottomBG.frame.size.width, MAXFLOAT)];
    bottomLabel.frame = CGRectMake(0, (bottomBG.frame.size.height - imSize.height)/2.0, bottomBG.frame.size.width, imSize.height);
    bottomLabel.textAlignment = NSTextAlignmentCenter;
    
}

-(void)setModel:(id)model {
    
    HCVipModel *mm = (HCVipModel *)model;
    NSString *vip = [NSString stringWithFormat:@"%@",mm.type];
    if ([vip isEqualToString:@"年卡"]) {
        
        imageView.image = [UIImage imageNamed:@"happy_vip_vipbgc"];
        label.text = [NSString stringWithFormat:@"%@ 天",mm.data];
        [label setFont:YBKSystemFont(YBKAdaptiveFont(14)) childrenString:@"天"];
        [self setLabelCenter:label];
        
    }else if([vip isEqualToString:@"次卡"]){
        
        imageView.image = [UIImage imageNamed:@"happy_vip_vipbgcc"];
        label.text = [NSString stringWithFormat:@"%@ 次",mm.data];
        [label setFont:YBKSystemFont(YBKAdaptiveFont(14)) childrenString:@"次"];
        [self setLabelCenter:label];

    }else if ([vip isEqualToString:@"月卡"]) {
        
        imageView.image = [UIImage imageNamed:@"月卡"];
        label.text = [NSString stringWithFormat:@"%@ 天",mm.data];
        [label setFont:YBKSystemFont(YBKAdaptiveFont(14)) childrenString:@"天"];
        [self setLabelCenter:label];

    }else if ([vip isEqualToString:@"季卡"]) {
        
        imageView.image = [UIImage imageNamed:@"季卡"];
        label.text = [NSString stringWithFormat:@"%@ 天",mm.data];
        [label setFont:YBKSystemFont(YBKAdaptiveFont(14)) childrenString:@"天"];
        [self setLabelCenter:label];

    }else if ([vip isEqualToString:@"半年卡"]){

        imageView.image = [UIImage imageNamed:@"图层-210_01"];
        label.text = [NSString stringWithFormat:@"%@ 天",mm.data];
        [label setFont:YBKSystemFont(YBKAdaptiveFont(14)) childrenString:@"天"];
        [self setLabelCenter:label];

    }
    else if ([vip isEqualToString:@"储值卡"]) {
    
        dateLabel.hidden = NO;
        imageView.image = [UIImage imageNamed:@"mine_vip_storagecard"];
        label.text = [NSString stringWithFormat:@"余额:%@元",mm.money];
        dateLabel.text = [NSString stringWithFormat:@"剩余期限:%@天",mm.data];
        [label setFont:YBKSystemFont(YBKAdaptiveFont(14)) childrenString:@"元"];
        [dateLabel setFont:YBKSystemFont(YBKAdaptiveFont(14)) childrenString:@"天"];
    }
    bottomLabel.text = [NSString stringWithFormat:@"%@",mm.number];
}

- (void)setLabelCenter:(UILabel *)customLabel {

    [customLabel setFrame:CGRectMake(0, 10, midView.frame.size.width, midView.frame.size.height/2.0)];
    dateLabel.hidden = YES;
}


@end
